#ifndef VIDEORECEIVER_H
#define VIDEORECEIVER_H

#include <QObject>
#include <QProcess>
#include <QWidget>
#include <QString>

class VideoReceiver : public QObject
{
    Q_OBJECT

public:
    explicit VideoReceiver(QObject *parent = nullptr);
    ~VideoReceiver();

    // 初始化和配置
    bool initialize();
    void setMulticastAddress(const QString& address, int port);
    void setVideoWidget(QWidget* widget);

    // 接收控制
    bool startReceiving();
    void stopReceiving();
    bool isReceiving() const;

signals:
    void receivingStarted();
    void receivingStopped();
    void errorOccurred(const QString& error);

private slots:
    void onFFplayFinished(int exitCode, QProcess::ExitStatus exitStatus);
    void onFFplayError(QProcess::ProcessError error);
    void onFFplayOutput();
    void onFFplayErrorOutput();

private:
    void setupFFplayProcess();
    void buildFFplayArguments();
    void createSDPFile();

private:
    QProcess* ffplayProcess;
    QWidget* videoWidget;
    
    // 配置参数
    QString multicastAddress;
    int port;
    
    // 状态
    bool isReceivingFlag;
    
    // FFplay参数
    QStringList ffplayArguments;
};

#endif // VIDEORECEIVER_H
